<template>
  <el-dropdown trigger="click" @command="onCommand">
    <slot></slot>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item
          v-for="item of items"
          :key="item.value"
          :command="`${prefix}-${item.value}`"
          :disabled="value === item.value"
        >
          <el-icon v-if="item.icon"><component :is="item.icon" /></el-icon> {{ item.label }}
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script setup lang="ts" generic="T">
import type { Component } from 'vue'

defineProps<{
  value: T
  prefix: string
  items: ReadonlyArray<{ value: string; icon?: Component; label: string }>
  // items: readonly { value: string; icon?: Component; label: string }[]
}>()

const emit = defineEmits<{
  command: [value: string]
}>()

const onCommand = (command: string) => {
  emit('command', command)
}
</script>

<style scoped lang="scss"></style>
